package lamnhungoc.controller;



import lamnhungoc.form.validator.DangKyFormValidator;
import lamnhungoc.pojo.KhachHang;
import lamnhungoc.service.KhachHangService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.support.SessionStatus;
import org.springframework.web.servlet.ModelAndView;



@Controller
public class DangKyController {
	@Autowired
	private KhachHangService khachHangService;
	
	@Autowired
	private DangKyFormValidator dangKyFormValidator;
	
	@RequestMapping(value="/Trang-Dang-Ky", method=RequestMethod.GET)
	public ModelAndView hienThiTrangDangKy()
	{
		ModelAndView mav = new ModelAndView("Trang-Dang-Ky");
		KhachHang kh = new KhachHang();
		mav.getModelMap().put("Trang-Dang-Ky", kh);
		return mav;
	}
	@RequestMapping(value="/Trang-Dang-Ky", method=RequestMethod.POST)
	public String create(@ModelAttribute("Trang-Dang-Ky")KhachHang khachhang, BindingResult result, SessionStatus status)
	{
		dangKyFormValidator.validate(khachhang, result);
		if (result.hasErrors()) 
		{				
			return "Trang-Dang-Ky";
		}
		khachHangService.createKhachHang(khachhang);
		status.setComplete();
		return "Trang-Nhat";
	}
	
	
	


}
